package com.jeesite.modules.digitalize.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.modules.digitalize.entity.DigitalizeComponentCompare;
import com.jeesite.modules.digitalize.entity.dto.DigitalizeComponentCompareDTO;
import com.jeesite.modules.digitalize.entity.dto.DigitalizeComponentCompareQuery;
import com.jeesite.modules.digitalize.entity.dto.system.reviewproces.DeleteIdListDTO;
import com.jeesite.modules.digitalize.service.DigitalizeComponentCompareService;
import com.jeesite.modules.digitalize.util.bimface.BimFaceUtils;
import com.jeesite.modules.digitalize.util.response.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "数字-构件对比模块")
@RestController
@RequestMapping("${adminPath}/digitalize/componentCompare")
public class DigitalizeComponentCompareController {
    /**
     * 服务对象
     */
    @Resource
    private DigitalizeComponentCompareService digitalizeComponentCompareService;


    @Resource
    private BimFaceUtils bimFaceUtils;
    @ApiOperation("对比列表")
    @GetMapping("/pageList")
    public ResultVo<Page<DigitalizeComponentCompare>> pageList(@Validated DigitalizeComponentCompareQuery dto) {
        Page<DigitalizeComponentCompare> page = new Page<DigitalizeComponentCompare>(dto.getPageNo(), dto.getPageSize());
        return ResultVo.success(this.digitalizeComponentCompareService.lambdaQuery().like(StringUtils.isNotBlank(dto.getName()), DigitalizeComponentCompare::getName, dto.getName()).page(page));
    }


    @GetMapping("/info/{id}")
    public ResultVo<DigitalizeComponentCompare> selectOne(@PathVariable Long id) {
        return ResultVo.success(this.digitalizeComponentCompareService.getById(id));
    }

    @ApiOperation("发起对比")
    @PostMapping("/add")
    public ResultVo add(@Validated @RequestBody DigitalizeComponentCompareDTO digitalizeComponentCompare) {
        DigitalizeComponentCompare digitalizeComponentCompare1 = BeanUtil.copyProperties(digitalizeComponentCompare, DigitalizeComponentCompare.class);
        digitalizeComponentCompare1.setStatus("0");
        return digitalizeComponentCompareService.saveCompare(digitalizeComponentCompare1);
    }

    @ApiOperation("回调")
    @GetMapping("/callback")
    public ResultVo callback(Long fileId,
                             Long integrateId,
                             Long compareId,
                             String status) {
        return ResultVo.success(digitalizeComponentCompareService.callback(fileId,integrateId,compareId,status));
    }

    @ApiOperation("删除数据")
    @PostMapping("/delete")
    public ResultVo deleteList(@RequestBody @Validated DeleteIdListDTO dto) {
        return ResultVo.success(this.digitalizeComponentCompareService.removeByIds(dto.getIdList()));
    }

    @ApiOperation(value = "导出")
    @PostMapping("/export/{id}")
    public void export(HttpServletResponse response, @PathVariable Long id) {
        digitalizeComponentCompareService.export(response, id);
    }
}

